home *** CD-ROM | disk | FTP | other *** search
/ L' Effet Pommier 3 / L'Effet Pommier - Volume 03.iso / Programmation / Alpha ƒ / Tcl / UserCode / canon.tcl next >
Text File  |  1994-03-08  |  4KB  |  164 lines

  1. # FILE: canon.tcl
  2. #
  3. # LAST UPDATED: 12/07/92 6:37:34 AM
  4. #
  5. # This file contains the following TCL procedure(s):
  6. #
  7. #     canon    -- forces identifiers to canonical form
  8.  
  9. # SYNOPSIS:
  10. #    Canonize identifiers
  11. # DESCRIPTION:
  12. #    Searches & replaces identifiers with new/corrected spelling.
  13. #    May be used to force language keywords to a particular alphabetic
  14. #    case.  Simplifies ensuring case consistency.
  15. #    
  16. #    Advantages of using this procedure over simple search/replace
  17. #    are:
  18. #    
  19. #    A. Defaults to word boundary replacements
  20. #    B. Batch operation
  21. #    C. Forces alphabetic case
  22. # INSTRUCTIONS:
  23. #    Simply:
  24. #    1. Create several lines with the old and new words.  List may
  25. #       start with # treated as a comment.  Example:
  26. #        oldName newName
  27. #    2. Select lines containing old and new words.
  28. #    3. Invoking canon will change EVERY occurence.  Example:
  29. #        newName newName
  30. #    4. If you want the original text back, it is saved in the named clipboard
  31. #       called "canon-text"
  32. #    Options:
  33. #        -a = any occurence of oldName (not restricted to word boundaries)
  34. #        -c = case insensitive
  35. #        -r = use regular expressions
  36. #    If any line in the list has a single word only, then the canonization
  37. #    forces any case insensitive version of that word to the specific case.
  38.  
  39. # COPYRIGHT:
  40. #
  41. #    Copyright ⌐ 1992 by David C. Black
  42. #    All rights reserved.
  43. #
  44. #    Redistribution and use in source and binary forms are permitted
  45. #    provided that the above copyright notice and this paragraph are
  46. #    duplicated in all such forms and that any documentation,
  47. #    advertising materials, and other materials related to such
  48. #    distribution and use acknowledge that the software was developed
  49. #    by David C. Black.
  50. #
  51. #    THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
  52. #    IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  53. #    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  54. #
  55. ################################################################################
  56.  
  57. # AUTHOR
  58. #
  59. #    David C. Black
  60. #    Internet: black@mpd.tandem.com (preferred)
  61. #    GEnie:    D.C.Black
  62. #    USnail:   6217 John Chisum Lane, Austin, TX 78749
  63. #
  64. ################################################################################
  65.  
  66. # HISTORY
  67. #                  
  68. # modified who rev reason
  69. # -------- --- --- ------
  70. # 12/03/92 DCB 1.0 Original
  71. ################################################################################
  72.  
  73. proc canon {args} {
  74.     global searchStr
  75.     global replaceStr
  76.     global ignoreCase
  77.     global regExpr
  78.     global forward
  79.     global ignoreCase
  80.     global matchWords
  81.     shadowVar regExpr
  82.     shadowVar forward
  83.     shadowVar ignoreCase
  84.     shadowVar matchWords
  85.     saveVars
  86.     if {[getPos] == [selEnd]} {
  87.         alertnote "Nothing selected"
  88.         return
  89.     }
  90.     watchCursor
  91.     set regExpr 0
  92.     set forward 1
  93.     set ignoreCase 0
  94.     set matchWords 1
  95.     foreach arg $args {
  96.         case $arg {
  97.             {-a} {
  98.                 set matchWords 0
  99.             }
  100.             {-c} {
  101.                 set ignoreCase 1
  102.             }
  103.             {-r} {
  104.                 set regExpr 1
  105.             }
  106.         }
  107.     }
  108.  
  109.     # Get the canonical text list
  110.     beginningLineSelect
  111.     endLineSelect
  112.     set text [getSelect]
  113.     clear
  114.     
  115.     # Save copy
  116.     global clipBoards
  117.     enableMenuItem Misc "pasteNamedClipboard" on
  118.     set clipBoards(canon-text) $text
  119.  
  120.     set lines [split $text "\r"]
  121.  
  122.     # Split the text list into a proper TCL list
  123.     foreach line $lines {
  124.         regsub "^#" $line "" line
  125.         set line [string trim $line]
  126.         regsub "\[ \t\]+" $line " " line
  127.         set bullet [split $line]
  128.         case [llength $bullet] {
  129.         {2} {
  130.             lappend bullet $ignoreCase
  131.             lappend ammo $bullet
  132.         }
  133.         {1} {
  134.             lappend ammo [list $bullet $bullet 1]
  135.         }
  136.         }
  137.     }
  138.     
  139.     # Do the work
  140.     foreach pair $ammo {
  141.         set searchStr [lindex $pair 0]
  142.         set replaceStr [lindex $pair 1]
  143.         set ignoreCase $ignoreCase
  144.         goto 0
  145.         searchRall
  146.     }
  147.     restoreVars
  148. }
  149. #endproc canon
  150.  
  151. ################################################################################
  152.